package com.yj.springbootfastdfs.service;

import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.Set;

@Service
public class FdfsServiceImpl implements FdfsService {

    @Resource
    private FastFileStorageClient fastFileStorageClient;

    @Override
    public String upload(MultipartFile file, String fileExtName,Set<MetaData> metaDataSet) throws Exception {
        //InputStream inputStream, 文件输入流
        // long fileSize, 文件大小
        // String fileExtName, 文件后缀名
        // Set<MetaData> metaDataSet 文件的元素据，额外数据
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(),file.getSize(),fileExtName, metaDataSet);
        String path = storePath.getFullPath();
        return path;
    }
}
